package com.android.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.util.Log;

public class SmsReceiver extends BroadcastReceiver {

	private static final String TAG = "SMSReceiver"; 
	static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; 
	
	
	public void onReceive(Context context, Intent intent) {
		Log.e(TAG, "++ onReceive ++");
		Bundle bundle = intent.getExtras();
		SmsMessage[] msgs = null;
		String contenido = "CONTENIDO";

		if (bundle != null) {
			Object[] pdus = (Object[]) bundle.get("pdus");
			SmsMessage msgss = SmsMessage.createFromPdu((byte[]) pdus[0]);
			
//            for (int j = 0; j < comparador.length; j++) {

            	if (msgss.getMessageBody().toString().equals("arranca"))
            	{
    				Log.e(TAG, "++ display SMS ++");
            		// ---display the new SMS message---
//    				Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
//    				context.startActivity(new Intent(context, Receiver.class));
//    				Toast.makeText(context, " LANZANDO ACTIVIDAD BOTONES", Toast.LENGTH_SHORT).show();
    				Intent smsActivityIntent = new Intent(context, com.android.activity.Receiver.class);
    				smsActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//  CON ESTE NO FUNCIONA  				smsActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    				smsActivityIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    		        context.startActivity(smsActivityIntent);		
    		        
    				
//    	            ReceiverSMS.this.finish();
            	}
            	
//            }

		}
	}

}
